package com.ruoyi.framework.aspectj;

import com.ruoyi.common.exception.CustomException;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.mapper.SysConfigMapper;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName CheckSwitchAspect
 * @Description TODO
 * @Author zz
 * @Date 2024/2/21
 **/
@Component
@Aspect
public class CheckSwitchAspect {
    @Autowired
    @SuppressWarnings("all")
    private SysConfigMapper sysConfigMapper;

    @Pointcut("@annotation(com.ruoyi.common.annotation.CheckSwitch)")
    public void pointCut() {
    }

    @Before("pointCut()")
    public void before(JoinPoint joinPoint){
        SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique("shutdown_switch");
        if(sysConfig != null && sysConfig.getConfigValue().equals("0")){
            throw new CustomException("服务正在升级中");
        }
    }
}
